define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'goods.library_goods_relation/index',
        add_url: 'goods.goods2/index?library_id='+library_id,
        edit_url: 'goods.library_goods_relation/edit',
        delete_url: 'goods.library_goods_relation/delete',
        export_url: 'goods.library_goods_relation/export',
        modify_url: 'goods.library_goods_relation/modify',
        see_goods_url:'goods/edit',
    };
    var form = layui.form;

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar:['refresh','add','delete'],
                where:{'library_id':library_id},
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID',fieldAlias:'ggr.id',width: 80},
                    {field: 'shop_name', title: '商品所属商家',width: 120,search:false},
                    {field: 'category_name', title: '商品分类',fieldAlias:'gc.name',width: 120},
                    {field: 'goods_library_id', title: '商品库id',hide:true,search:false},
                    {field: 'img', title: '商品主图',imageHeight: 80,templet: ea.table.image,search:false},
                    {field: 'goods_name', title: '商品',search:true},
                    {field: 'show_price', title: '商品价格'},
                    {field: 'goods_id', title: '商品id',hide:true,search:false},
                    {
                        field: 'status', title: '状态',fieldAlias:'ggr.status', selectList: ['不展示', '展示', '待审核'], templet: function (k, v) {
                            switch (k.status) {
                                case 1:
                                    return '<span class="layui-badge layui-bg-green">展示</span>';
                                    break;
                                case 0:
                                    return '<span class="layui-badge">不展示</span>';
                                    break;
                                default:
                                    return '<span class="layui-badge layui-bg-gray">待审核</span>';
                                    break;
                            }
                        }
                    },
                    // {field: 'create_time',fieldAlias:'ggr.create_time', title: '添加时间',search:'range'},
                    {width: 250, title: '操作', templet: ea.table.tool,
                        operat: [
                            [{
                                text: '查看商品',
                                url: init.see_goods_url,
                                method: 'open',
                                auth: 'see_goods',
                                fieldExtra:{'id':'goods_id'},
                                class: 'layui-btn layui-btn-xs layui-btn-normal',
                                extend: 'data-full="true"',
                            }],
                            'edit',
                            'delete'
                        ]
                    },
                ]],
				done: function (){
                    $(".layui-table-body>table>tbody>tr").each(function (index, val) {
                        $($(".layui-table-fixed .layui-table-body table tr")[index]).height($(val).height());
                    });
                },
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});